package com;

import com.dao.UserDao;
import com.pojo.User;
import com.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@ComponentScan//扫描项目中的bean类
@Configuration//说明本项目是IOC配置类

@Configuration
@ComponentScan
@EnableAspectJAutoProxy
@EnableWebMvc
public class AppConfig {
    public static void main(String[] args) {
        ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
//        User user = (User) ctx.getBean(User.class);
//        System.out.println(user);
        UserService userService = ctx.getBean(UserService.class);
        boolean flag = userService.login("张三","123");
        if (flag) {
            System.out.println("登录成功");
        }else {
            System.out.println("登录失败");
        }
        UserDao userDao = ctx.getBean(UserDao.class);
        userDao.select();
        userDao.update();
        userDao.delete();
        userDao.insert();
        @Bean
        public InternalResourceViewResolver viewResolver() {
            InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
            viewResolver.setPrefix("/WEB-INF/pages/");//模板文件位置
            viewResolver.setSuffix(".jsp");// 自动解析后缀名
            return viewResolver;
        }
    }
}
\ No newline at end of file
